var control = [0,0,0];

function setTipo(op){
           
  lastTipo=(op-1);
    
}


function saveSeccion(){
   var nombre=document.getElementById("txtnombre").value;
   var encabe=document.getElementById("txtencabezado").value;
   var sel=document.getElementById("dropEncuesta");
   var encuesta=sel.options[sel.selectedIndex].value;
   var url=url_base + "/encuestas/edicion_encuestas_controller/saveSeccion/"+encuesta+"/"+nombre+"/"+encabe;
   peticionAjax(url,1);
}

var bandera=0;
function crateOption(op,grup,index,value){
  var div = document.createElement('div');
  
  if (op==1){
      div.innerHTML='<input type="radio"  name="group1" disabled="" > <input name="txtopc'+(index + 1)+'" required=""  title="Escribir Opcion." placeholder="Opcion '+(index + 1)+'" class="control-label editables1" value="'+value+'"><br>';
      grup.appendChild(div);
      grup.parentNode.parentNode.parentNode.getElementsByClassName("options")[0].value=grup.getElementsByTagName("div").length;
  }
  else if(op==3){
     div.innerHTML='<br/><input type="radio" name="group1" disabled=""> <a style="text-decoration: none; color: black;"> Otros </a> <input type="text"  disabled="" class="editables1"><input type="text" name="otro" style="display:none;" value="otrosa"/><br>';
     grup.appendChild(div);    
  } 
  else if(op==4){
     div.innerHTML='<br/><input type="checkbox" name="group1" disabled=""> <a style="text-decoration: none; color: black;"> Otros </a> <input type="text"  disabled="" class="editables1"><input type="text" name="otro" style="display:none;" value="otrosa"/><br>';
     grup.appendChild(div);    
  }  
  else{
     div.innerHTML='<input type="checkbox" name="group1" disabled="" > <input name="txtopc'+(index + 1)+'" required=""  title="Escribir Opcion." placeholder="Opcion '+(index + 1)+'" class="control-label editables1" value="'+value+'"><br>';
     grup.appendChild(div);
     grup.parentNode.parentNode.parentNode.getElementsByClassName("options")[0].value=grup.getElementsByTagName("div").length;
  }   
      
}

function createTR(table,op,manageF,value,op2,opc3){
      var indexTR =table.getElementsByTagName("tbody")[0].getElementsByTagName("tr").length;       
      var indexTD =table.getElementsByTagName("tr")[0].getElementsByTagName("th").length;
      var tr = document.createElement("tr");
        if (op2==1){
            indexTD--;            
        }
        
         for(var i=0;i<indexTD;i++){
           if(i==0){
              if(opc3==1)
                  tr.innerHTML+='<td><a style="text-decoration: none; color: black;"> Otros </a> <input type="text"  disabled="" class="editables3"><input type="text" name="otros" style="display:none;" value="otrosa"/></td>';
              else    
                tr.innerHTML+='<td><input required=""  title="LLenar Campo." name="txtopc'+(indexTR+1)+'" placeholder="Fila" class="control-label editables2" value="'+ value +'"></td>';
          }else{
              switch(op){
                  case 1: 
                      tr.innerHTML+='<td><input type="radio" name="group1" disabled="" ></td>';
                  break;
                  
                  case 2: 
                       tr.innerHTML+='<td><input type="checkbox" name="group1" disabled="" ></td>';
                  break;
                  case 3: 
                       tr.innerHTML+='<td><input type="text" name="group1" disabled="" class="editables3"></td>';
                  break;
                 
              }
                
          } 
       } 
       if (op2==1){
         tr.innerHTML+='<td><input type="text" name="group1" disabled="" class="editables3"></td>';        
       }
       
       if (opc3==1){
         table.getElementsByTagName("tbody")[0].appendChild(tr);
       }else{
            table.getElementsByTagName("tbody")[0].appendChild(tr);
            manageF.value=table.getElementsByTagName("tbody")[0].getElementsByTagName("tr").length;  
       }
}
function deleteTR(table,manageF){
    var trs =table.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
    if(trs.length > 1){
        table.getElementsByTagName("tbody")[0].removeChild(trs[trs.length-1]);
         manageF.value=table.getElementsByTagName("tbody")[0].getElementsByTagName("tr").length; 
    }
}

function createTH(table,op,mangeC,value){
    var trs =table.getElementsByTagName("tr");
    for(var i=0;i<trs.length;i++){
        
        if(i==0){
            var th=document.createElement("th");
            var index=trs[i].getElementsByTagName("th").length;
            if(op!=4){
             th.innerHTML+='<input required=""  title="Llenar Campo." name="txtcab'+(index + 1)+'" placeholder="Cabecera" class="control-label editables2 alert-info" value="'+ value +'">';                
             trs[i].appendChild(th);
             mangeC.value=trs[i].getElementsByTagName("th").length;
           }else{
             th.innerHTML+='<input required=""  title="Llenar Campo." name="otro" placeholder="Otros" class="control-label editables2 alert-info" value="'+ value +'">';                
             trs[i].appendChild(th); 
             control[lastTipo]=1;
           }
           
          
        }else{
            var td =document.createElement("td");
            switch(op){
                  case 1: 
                      td.innerHTML+='<input type="radio"  name="group1" disabled="" >';
                  break;                  
                  case 2: 
                      td.innerHTML+='<input type="checkbox"  name="group1" disabled="" >';
                  break;  
                  case 3: 
                      td.innerHTML+='<input type="text" name="group1" disabled="" class="editables3">';
                  break;
                  case 4: 
                      td.innerHTML+='<input type="text" name="group1" disabled="" class="editables3">';
                  break; 
                  
              }
                       
            trs[i].appendChild(td);
        }
        
    }
        
}


function deleteTH(table,op,mangeC){
    var trs =table.getElementsByTagName("tr");
    for(var i=0;i<trs.length;i++){
        
        if(i==0){
             
              var ths=trs[i].getElementsByTagName("th");
              
              if (ths.length > 3){
                  
                  trs[i].removeChild(ths[ths.length-1]); 
                  mangeC.value=trs[i].getElementsByTagName("th").length;
              }
        }else{
            var tds=trs[i].getElementsByTagName("td");
              if (tds.length > 3){
                  trs[i].removeChild(tds[tds.length-1]);                  
              }
        }
        
    }
        
}





function addOther(btn,op){
   var parent=btn.parentNode.parentNode.parentNode;  
   var radios=parent.getElementsByClassName("controls")[0].getElementsByTagName("div");
   crateOption(op,parent.getElementsByClassName("controls")[0], radios.length,"");

   parent.getElementsByClassName("add")[0].style.display="none";
   btn.style.display="none";
   
    
}
function addOtherTR(btn,op){    
   var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;   
   createTR(parent.getElementsByTagName("table")[0], op,parent.getElementsByClassName("filas")[0],"",control[lastTipo],1);
   parent.getElementsByClassName("addF")[0].style.display="none";
   btn.style.display="none"; 
}
function addOtherTH(btn,op){
 var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;   
 createTH(parent.getElementsByTagName("table")[0], op,parent.getElementsByClassName("columnas")[0],"",op-1);  
parent.getElementsByClassName("add")[0].style.display="none";
btn.style.display="none"; 
  
}

function addTH(btn,op){
 var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;   
 createTH(parent.getElementsByTagName("table")[0], op,parent.getElementsByClassName("columnas")[0],"");   
  
}

function quitTH(btn,op){    
    var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;   
    deleteTH(parent.getElementsByTagName("table")[0], op,parent.getElementsByClassName("columnas")[0]);
    parent.getElementsByClassName("other")[0].style.display="inline-block";
    parent.getElementsByClassName("add")[0].style.display="inline-block";
     control[lastTipo]=0;
    
}

function addTR(btn,op){    
   var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;   
   createTR(parent.getElementsByTagName("table")[0], op,parent.getElementsByClassName("filas")[0],"",control[lastTipo],0);
}

function quitTR(btn,op){
    var parent=btn.parentNode.parentNode.parentNode.parentNode.parentNode;
    deleteTR(parent.getElementsByTagName("table")[0],parent.getElementsByClassName("filas")[0]);
    parent.getElementsByClassName("otherF")[0].style.display="inline-block";
    parent.getElementsByClassName("addF")[0].style.display="inline-block";
}

function addRadio(btn){
  var parent=btn.parentNode.parentNode.parentNode;  
   var radios=parent.getElementsByClassName("controls")[0].getElementsByTagName("div");
   crateOption(1,parent.getElementsByClassName("controls")[0], radios.length,"");
 }

function quitRadio(btn){
    var parent=btn.parentNode.parentNode.parentNode;  
    var radios=parent.getElementsByClassName("controls")[0].getElementsByTagName("div");
     if(radios.length > 2){
      parent.getElementsByClassName("controls")[0].removeChild(radios[radios.length-1]);
     }
     
     parent.parentNode.parentNode.getElementsByClassName("options")[0].value=parent.getElementsByClassName("controls")[0].getElementsByTagName("div").length;
     parent.getElementsByClassName("other")[0].style.display="inline-block";
      parent.getElementsByClassName("add")[0].style.display="inline-block";
}

function addCheck(btn){
  var parent=btn.parentNode.parentNode.parentNode;  
   var radios=parent.getElementsByClassName("controls")[0].getElementsByTagName("div");
   crateOption(2,parent.getElementsByClassName("controls")[0], radios.length,""); 
}

function quitCheck(btn){
    var parent=btn.parentNode.parentNode.parentNode;  
    var radios=parent.getElementsByClassName("controls")[0].getElementsByTagName("div");
    if(radios.length > 2){
      parent.getElementsByClassName("controls")[0].removeChild(radios[radios.length-1]);
    }
    parent.parentNode.parentNode.getElementsByClassName("options")[0].value=parent.getElementsByClassName("controls")[0].getElementsByTagName("div").length;
    parent.getElementsByClassName("other")[0].style.display="inline-block";
    parent.getElementsByClassName("add")[0].style.display="inline-block";
}

function changeOption(sel,op){
    var value=sel.options[sel.selectedIndex].value;
    if(op==1){
        if(value==1){
         document.getElementById("texto").style.display="inline";
         document.getElementById("numero").style.display="none";
         document.getElementById("fecha").style.display="none";         
        }else if(value==2){
         document.getElementById("texto").style.display="none";
         document.getElementById("numero").style.display="inline";
         document.getElementById("fecha").style.display="none";
        }else if(value==3){
          document.getElementById("texto").style.display="none";
          document.getElementById("numero").style.display="none";
          document.getElementById("fecha").style.display="inline";

        }else if(value==0){
         document.getElementById("texto").style.display="none";
         document.getElementById("numero").style.display="none";
         document.getElementById("fecha").style.display="none";

        }
    }else
       if(value==1){
         
         document.getElementById("textoT").style.display="inline";
         document.getElementById("numeroT").style.display="none";
         document.getElementById("fechaT").style.display="none";         
        }else if(value==2){
         document.getElementById("textoT").style.display="none";
         document.getElementById("numeroT").style.display="inline";
         document.getElementById("fechaT").style.display="none";
        }else if(value==3){
          document.getElementById("textoT").style.display="none";
          document.getElementById("numeroT").style.display="none";
          document.getElementById("fechaT").style.display="inline";

        }else if(value==0){
         document.getElementById("textoT").style.display="none";
         document.getElementById("numeroT").style.display="none";
         document.getElementById("fechaT").style.display="none";

        }
    
}


function peticionAjax(url,opc) {
    $.ajax({
        type: "GET",
        url: url,
        data:"",
        dataType: "html",
        contentType: "application/x-www-form-urlencoded",
        success: function (datos) {
           alert(datos);
        }
    });
}

function eliminar(id,tipo,sub){
    var form = document.createElement("form");  
    var url=document.getElementById("urlBase").value;
    url+="eliminarPregunta/"+id+"/"+tipo+"/"+sub;
    
    
    
    form.action=url;
   
    confirm("Confirmacion"+id,"¿Eliminar Pregunta?", function(confirmed) {
        
        if((confirmed)){
           fake_load();
          form.submit();
           return true;
           
          }
        else
         return false;   
        });   
    
}

function eliminarSeccion(id){
    var form = document.createElement("form");  
    var url=document.getElementById("urlBase").value;
    url+="eliminarSeccion/"+id;
    
    
    
    form.action=url;
   
    confirm("Confirmacion"+id,"¿Eliminar Pregunta?", function(confirmed) {
        
        if((confirmed)){
           fake_load();
          form.submit();
           return true;
           
          }
        else
         return false;   
        });   
    
}


function edit(id){
   
  var input_json= document.getElementById(id).getElementsByClassName("json")[0];
  var jsons=input_json.value.split(";");   
  var pregunta=eval('(' + jsons[0] + ')');
 
  
 if(pregunta.TipoPregunta==1){
                  
          editPreguntaAbierta(jsons);
         
         
 }else if(pregunta.TipoPregunta==2){
         
         
          editPreguntaOpcionSencilla(jsons);
         
         
 }else if(pregunta.TipoPregunta==3){
         
         
          editPreguntaOpcionMultiple(jsons);
         
         
 }else if(pregunta.TipoPregunta==4){
           lastTipo=1;
           var tablaAux=document.getElementById(id).getElementsByTagName("tbody")[0];           
           editPreguntaTablaOpcionSencilla(jsons,tablaAux,id);
         
         
 }else if(pregunta.TipoPregunta==5){
          lastTipo=2;
          var tablaAux=document.getElementById(id).getElementsByTagName("tbody")[0];           
           editPreguntaTablaOpcionMultiple(jsons,tablaAux,id);
         
         
 }else if(pregunta.TipoPregunta==6){
          lastTipo=3;
          var tablaAux=document.getElementById(id).getElementsByTagName("tbody")[0];           
           editPreguntaTablaOpcionAbierta(jsons,tablaAux,id);         
 }                    


    
}      
       
function editPreguntaAbierta(jsons){
    var pregunta=eval('(' + jsons[0] + ')');
    var validacion=eval('(' + jsons[1] + ')');
    var body=document.getElementById("addPA").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];
    $("#modal").removeClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
     
    var enc=bodymodal.getElementsByClassName("inputs");
    enc[0].remove(0);
    enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
    enc[1].value=pregunta.Texto;
    enc[2].value=pregunta.TextoAuxiliar;
    if(pregunta.Requerida==1)
         enc[3].checked=true;
     else   
        enc[3].checked=false;
    
    
    if(validacion.TipoDato==1){
        enc[5].value=validacion.Mascara;
    }else if(validacion.TipoDato==2){
        enc[6].value=validacion.ValorInicial;
        enc[7].value=validacion.ValorFinal;
           
    } else if(validacion.TipoDato==3) {
        enc[8].value=validacion.ValorInicial;
        enc[9].value=validacion.ValorFinal;            
    }
       
    enc[4].selectedIndex=(validacion.TipoDato-1);    
    changeOption(enc[4], 1);    
    
    var form=bodymodal.getElementsByTagName("form")[0];
   
    var url=document.getElementById("urlBase").value;
    form.action=url+"/editPreguntaAbierta/"+pregunta.idPregunta;
    
  
    $("#modal").modal("show");   
 
}     

 function saveEdition() {
    fake_load();
    var form=document.getElementById("modal").getElementsByTagName("form")[0];
    form.submit(); 
 }

 function editPreguntaOpcionSencilla(jsons){
    var pregunta=eval('(' + jsons[0] + ')');
    var options=eval('(' + jsons[1] + ')');
   
    var body=document.getElementById("addOS").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];
   $("#modal").removeClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
  
  
     var enc=bodymodal.getElementsByClassName("inputs");
    enc[0].remove(0);
    enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
    enc[1].value=pregunta.Texto;
    enc[2].value=pregunta.TextoAuxiliar;
      if(pregunta.Requerida==1)
        enc[3].checked=true;
    else   
        enc[3].checked=false;
   
    var grup=bodymodal.getElementsByClassName("controls")[0];
    grup.innerHTML="";
  
    
    for(var i=0;i<options.length;i++)
      if(options[i].Otro!=1){
         crateOption(1,grup,i,options[i].Texto);
      }else{
         crateOption(3,grup,i,options[i].Texto); 
         
         bodymodal.getElementsByClassName("add")[0].style.display="none";
         bodymodal.getElementsByClassName("other")[0].style.display="none";
      }
    
   
   
    var form=bodymodal.getElementsByTagName("form")[0];
   
    var url=document.getElementById("urlBase").value;
    form.action=url+"/editPreguntaOpcionesS/"+pregunta.idPregunta;
    
  
    $("#modal").modal("show");    
 }
 
 function editPreguntaOpcionMultiple(jsons){
    var pregunta=eval('(' + jsons[0] + ')');
    var options=eval('(' + jsons[1] + ')');
   
    var body=document.getElementById("addOM").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];  
     $("#modal").removeClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
  
  
     var enc=bodymodal.getElementsByClassName("inputs");
   enc[0].remove(0);
   enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
   enc[1].value=pregunta.Texto;
    
    enc[2].value=pregunta.TextoAuxiliar;
      if(pregunta.Requerida==1)
        enc[3].checked=true;
    else   
        enc[3].checked=false;
   
    enc[4].value=pregunta.NumeroOpSeleccionable;
    var grup=bodymodal.getElementsByClassName("controls")[0];
    grup.innerHTML="";

   
    for(var i=0;i<options.length;i++)    
    if(options[i].Otro!=1){
        crateOption(2,grup,i,options[i].Texto);
        
      }else{
         crateOption(4,grup,i,options[i].Texto); 
         
         bodymodal.getElementsByClassName("add")[0].style.display="none";
         bodymodal.getElementsByClassName("other")[0].style.display="none";
      }
    var form=bodymodal.getElementsByTagName("form")[0];
  
   var url=document.getElementById("urlBase").value;
   form.action=url+"/editPreguntaOpcionesM/"+pregunta.idPregunta;
   
  
    $("#modal").modal("show");    
 }
 
 
 
  function editPreguntaTablaOpcionSencilla(jsons,tablaAux,id){
    var pregunta=eval('(' + jsons[0] + ')');
    var options=eval('(' + jsons[1] + ')');
   
    var body=document.getElementById("addTOS").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];
    $("#modal").addClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
 
 
    var enc=bodymodal.getElementsByClassName("inputs");
   enc[0].remove(0);
   enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
   enc[1].value=pregunta.tabla;

     if(pregunta.Requerida==1)
        enc[2].checked=true;
    else   
        enc[2].checked=false;


    var  tabla = pane_Pregunta.getElementsByTagName("table")[0];
  
     var auxrow=tabla.getElementsByTagName("thead")[0].getElementsByTagName("th");
 
    tabla.getElementsByTagName("tbody")[0].innerHTML="";
    
   for(var i=auxrow.length-1;i>0;i--)   
       tabla.getElementsByTagName("thead")[0].getElementsByTagName("tr")[0].removeChild(auxrow[i]);
  
   
     for(var j=0;j<options.length;j++){
       if(options[j].Otro==1)
         createTH(tabla,4,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
       else
        createTH(tabla,1,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
     }
         
   
     var label=tablaAux.getElementsByClassName("row5");  
     if(pregunta.Otro==1)
         var count=(label.length-1);
       else            
        var count=label.length;
     
     for(var k=0;k<count;k++){         
          if(options[options.length-1].Otro==1){
           createTR(tabla,1,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1);
           bodymodal.getElementsByClassName("add")[0].style.display="none";
           bodymodal.getElementsByClassName("other")[0].style.display="none";
           control[lastTipo]=1;
          }else{
           createTR(tabla,1,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,0);  
          }
     }
     
     
    if(pregunta.Otro==1){
         createTR(tabla,1,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1,1);
         bodymodal.getElementsByClassName("addF")[0].style.display="none";
         bodymodal.getElementsByClassName("otherF")[0].style.display="none";
         
     }
    var form=bodymodal.getElementsByTagName("form")[0]; 
    var url=document.getElementById("urlBase").value;
    form.action=url+"/editOpcionSencillaTable/"+id;
   
  
    $("#modal").modal("show");    
 }
 
 
  function editPreguntaTablaOpcionMultiple(jsons,tablaAux,id){
    var pregunta=eval('(' + jsons[0] + ')');
    var options=eval('(' + jsons[1] + ')');
   
    var body=document.getElementById("addTOM").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];
    $("#modal").addClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
 
    var enc=bodymodal.getElementsByClassName("inputs");

    enc[0].remove(0);
    enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
    enc[1].value=pregunta.tabla;
     
     if(pregunta.Requerida==1)
        enc[2].checked=true;
    else   
        enc[2].checked=false;
    enc[3].value=pregunta.NumeroOpSeleccionable;
    
    var  tabla = pane_Pregunta.getElementsByTagName("table")[0];
  
     var auxrow=tabla.getElementsByTagName("thead")[0].getElementsByTagName("th");
 
    tabla.getElementsByTagName("tbody")[0].innerHTML="";
    
   for(var i=auxrow.length-1;i>0;i--)   
       tabla.getElementsByTagName("thead")[0].getElementsByTagName("tr")[0].removeChild(auxrow[i]);
  
   
     for(var j=0;j<options.length;j++){
       if(options[j].Otro==1)
         createTH(tabla,4,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
       else
        createTH(tabla,2,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
     }
    // createTH(tabla,2,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
   
   
   
     var label=tablaAux.getElementsByClassName("row5");  
     if(pregunta.Otro==1)
         var count=(label.length-1);
       else            
        var count=label.length;
     
     for(var k=0;k<count;k++){         
          if(options[options.length-1].Otro==1){
           createTR(tabla,2,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1);
           bodymodal.getElementsByClassName("add")[0].style.display="none";
           bodymodal.getElementsByClassName("other")[0].style.display="none";
           control[lastTipo]=1;
          }else{
           createTR(tabla,2,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,0);  
          }
     }
     
      if(pregunta.Otro==1){
         createTR(tabla,2,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1,1);
         bodymodal.getElementsByClassName("addF")[0].style.display="none";
         bodymodal.getElementsByClassName("otherF")[0].style.display="none";
         
     }
    var form=bodymodal.getElementsByTagName("form")[0]; 
    var url=document.getElementById("urlBase").value;
    form.action=url+"/editOpcionMultipleTable/"+id;
   
  
    $("#modal").modal("show");    
 }
 
 
  
  function editPreguntaTablaOpcionAbierta(jsons,tablaAux,id){
    var pregunta=eval('(' + jsons[0] + ')');
    var validacion=eval('(' + jsons[1] + ')');
    var options=eval('(' + jsons[2] + ')');
   
    var body=document.getElementById("addTOA").getElementsByClassName("modal-body")[0];  
    var bodymodal=document.getElementById("modal").getElementsByClassName("modal-body")[0];
    $("#modal").addClass("anchoM");
    var pane_Pregunta=bodymodal.getElementsByClassName("tab-pane")[0];
    var pane_validacion=bodymodal.getElementsByClassName("tab-pane")[1];    
    
   
     pane_Pregunta.innerHTML = body.getElementsByClassName("tab-pane")[0].innerHTML;
     pane_validacion.innerHTML = body.getElementsByClassName("tab-pane")[1].innerHTML;
 
    var enc=bodymodal.getElementsByClassName("inputs");

    enc[0].remove(0);
    enc[0].selectedIndex=(enc[0].options.length-pregunta.Secuencia);
    enc[1].value=pregunta.tabla;
     
     if(pregunta.Requerida==1)
        enc[2].checked=true;
    else   
        enc[2].checked=false;
   
   
   if(validacion.TipoDato==1){
        enc[4].value=validacion.Mascara;
    }else if(validacion.TipoDato==2){
        enc[5].value=validacion.ValorInicial;
        enc[6].value=validacion.ValorFinal;
           
    } else if(validacion.TipoDato==3) {
        enc[7].value=validacion.ValorInicial;
        enc[8].value=validacion.ValorFinal;            
    }
       
    enc[3].selectedIndex=(validacion.TipoDato-1);    
    changeOption(enc[3], 2);  
    
    var  tabla = pane_Pregunta.getElementsByTagName("table")[0];
  
     var auxrow=tabla.getElementsByTagName("thead")[0].getElementsByTagName("th");
 
    tabla.getElementsByTagName("tbody")[0].innerHTML="";
    
   for(var i=auxrow.length-1;i>0;i--)   
       tabla.getElementsByTagName("thead")[0].getElementsByTagName("tr")[0].removeChild(auxrow[i]);
  
   
     for(var j=0;j<options.length;j++)
     createTH(tabla,3,bodymodal.getElementsByClassName("columnas")[0],options[j].Texto);
   
   
   
     var label=tablaAux.getElementsByClassName("row5");  
     if(pregunta.Otro==1)
         var count=(label.length-1);
       else            
        var count=label.length;
     
     for(var k=0;k<count;k++){         
          if(options[options.length-1].Otro==1){
           createTR(tabla,3,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1);
           bodymodal.getElementsByClassName("add")[0].style.display="none";
           bodymodal.getElementsByClassName("other")[0].style.display="none";
           control[lastTipo]=1;
          }else{
           createTR(tabla,3,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,0);  
          }
     }
     
      if(pregunta.Otro==1){
         createTR(tabla,3,bodymodal.getElementsByClassName("filas")[0], label[k].innerHTML,1,1);
         bodymodal.getElementsByClassName("addF")[0].style.display="none";
         bodymodal.getElementsByClassName("otherF")[0].style.display="none";
         
     }
     
    var form=bodymodal.getElementsByTagName("form")[0]; 
    var url=document.getElementById("urlBase").value;
    form.action=url+"/editTableAbierta/"+id;
   
  
    $("#modal").modal("show");    
 }
 
 